<?php
$field_names = array(
"library_id" => "Library ID",
      "photo" => "Photo",
      "date" => "Date",
      "title" => "Title",
);

require_once("ESSearch.php");
$service = new ESSearch("LTC");
$fields = $service->getFields();
$page_info = explode(" ", $_GET['tq']);
$page_size = $page_info[2];
$page = $page_info[4];
$tqx =$_GET['tqx'];
$tmp = explode(":", $tqx);
$reqId = $tmp[1];
if($page_size < 10 || $page_size > 50) $page_size = 10;
if($page < 1 ) $page_size = 0;
echo"	google.visualization.Query.setResponse({version:'0.6',reqId:'".$reqId."',status:'ok',table:{cols:[";
	$i = 0;
	foreach($fields as $field){
		echo "{id:'".$field["name"]."',label:'".$field_names[$field["name"]]."',type:'string'}";
		$i++;
		if($i<sizeof($fields))
			echo ",";
	}
	echo"rows:[";
	$i = 0;
	$results = $service->search("gif",$page_size, $page);
	foreach($results->results as $result){
		$j =0;
		$i++;
		echo "{c:[";
		foreach($result->fields as $field){
			echo "{v:".$field->value."}";
			$j++;
			if($j < sizeof($result->fields))
				echo ",";
		}
		echo"]}";
		if($i<sizeof($results->results))
			echo ",";
	}
	echo "]}});";
?>
